package com.addcn.android.design591.behavior;

import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;

import com.addcn.android.design591.activity.MainActivity;
import com.addcn.android.design591.utils.L;
import com.addcn.android.design591.utils.ScreenUtils;

/**
 * Created by yifeng on 16/9/23.
 * 这个类还不理解，后面回头来理解
 */

public class CustomExpandBehavior extends CoordinatorLayout.Behavior {
    private Context context;

    public CustomExpandBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        return dependency instanceof AppBarLayout;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        int screenHeight = ScreenUtils.getStatusHeight(context);
        int delta = dependency.getTop() - screenHeight;
        child.setTranslationY(-delta);
        return true;
    }
}
